//
//  ViewController.swift
//  AddressBook
//
//  Created by lanou3g on 15/10/6.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

import UIKit


class ViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {

    //声明tableview属性
    var addressTableView:UITableView?
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

    self.title = "联系人"
    
        addressTableView = UITableView(frame: self.view.frame, style: UITableViewStyle.Plain)
        
        var rightBarButton:UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Add, target: self, action: "didAddBarButtonClicked")
        
        
        navigationItem.rightBarButtonItem = rightBarButton
        
        addressTableView?.delegate = self
        addressTableView?.dataSource = self
        
        self.view .addSubview(addressTableView!)
    
    }

    //添加事件响应方法
    func didAddBarButtonClicked() {
        
        let addVC:AddViewController = AddViewController()
        
        navigationController?.pushViewController(addVC, animated: true)
        
    }
    
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        
        var cell = tableView.dequeueReusableCellWithIdentifier("cell")as? UITableViewCell
        
        if cell == nil{
            
            cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cell")
        }
        
        cell?.textLabel?.text = "sdfd"
        
        return cell!
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return 5
    }
    
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        
        let detailVC:DetailViewController = DetailViewController()
        navigationController?.showViewController(detailVC, sender: nil)
        
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

